package org.spring.activemq.demo;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Session;

import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.MessageConverter;

public class PaySettlementCoverter implements MessageConverter {
	public Object fromMessage(Message message) throws JMSException,
			MessageConversionException {
		ObjectMessage objMsg = (ObjectMessage) message;
		Hello hello = new Hello();
		hello.setId(objMsg.getStringProperty("id"));
		hello.setSaying(objMsg.getStringProperty("hello"));
		return hello;
	}

	public Message toMessage(Object obj, Session session) throws JMSException,
			MessageConversionException {
		Hello hello = (Hello) obj;
		ObjectMessage objMsg = session.createObjectMessage();
		objMsg.setJMSCorrelationID("123654");
		objMsg.setJMSReplyTo(objMsg.getJMSDestination());
		objMsg.setStringProperty("id", hello.getId());
		objMsg.setStringProperty("hello", hello.getSaying());
		return objMsg;
	}

}